<template>
  <div class="menus-manage">
    <!-- 面包屑 -->
    <div class="bread-crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item :to="{ path: '/home/reqFlow' }">我的申请</el-breadcrumb-item>
        <el-breadcrumb-item>请假申请</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="main-middle">
      <el-card class="box-card">
        <!-- 请假申请 -->
        <div class="card-title">请假申请</div>
        <el-form label-width="100px" :model="editForm" prop="day">
          <el-form-item label="请假天数">
            <el-input v-model="editForm.day"></el-input>
          </el-form-item>
          <el-divider></el-divider>
          <!-- <el-form-item label="选择审批人">
            <user-sel :users="users" @seluser="selUser"></user-sel>
          </el-form-item> -->
          <el-form-item label="优先级">
            <el-radio-group v-model="priority">
              <el-radio :label="0">普通</el-radio>
              <el-radio :label="1">重要</el-radio>
              <el-radio :label="2">紧急</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="消息推送">
            <el-checkbox v-model="message" label="站内消息通知"></el-checkbox>
            <el-checkbox v-model="wechat" label="企业微信通知"></el-checkbox>
            <el-checkbox v-model="email" label="邮件通知"></el-checkbox>
          </el-form-item>
        </el-form>
        <div class="card-line">
          <!-- 立即修改 -->
          <el-button type="primary" size="small" @click="onSubmit" :disabled="isSubmit">立即申请</el-button>
          <!-- 重置 初始化表单数据 -->
          <el-button size="small" @click="save" :disabled="isSubmit">暂存草稿</el-button>
          <!-- 返回 -->
          <el-button size="small" style="float:right" @click="goBack">返回</el-button>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
// 引入员工选择组件
import userSel from '@/components/UserSel/index.vue';
export default {
  // 注册组件
  components: {
    userSel
  },
  data () {
    return {
      isSubmit: false,
      editForm: {
        day: ''
      },
      priority: 0,
      message: true,
      wechat: '',
      email: '',
      // 获取所有用户
      users: []
    };
  },
  methods: {
    // 获取所有节点
    getNode () {
      // 初始数据源
      let nodeDB = this.$route.query.datas;
      // 当前节点ID
      let node = this.$route.query.node;
      // 获取所有节点数据
      let list = JSON.parse(nodeDB.flowJson);

      // 判断是否是初始节点
      if (node === 0) {
        // 获取下一节点
        let next = [];
        list.nodes.map(item => {
          if (item.index === node) {
            list.edges.map(key => {
              if (item.id === key.source) {
                next.push(key.target);
              }
            });
          }
        });
        let node = [];
        // 获得下一节点数据
        if (next.length > 0) {
          list.nodes.map(item => {
            if (item.id === next[0]) {
              node.push(item);
            }
          });

          if (node.length > 0) {
            if (node[0].type === '审批') {
              if (node[0].users === '发起人') {

              }
              if (node[0].users === '项目经理') {

              }
              if (node[0].users === '部门经理') {

              }
              if (node[0].users === '部门总监') {

              }
              if (node[0].users === '副总经理') {

              }
              if (node[0].users === '总经理') {

              }
            }
          }
        }
      }
    },
    // 提交
    onSubmit () {},
    // 数据暂存操作
    save () {
    },
    // 获取所有用户
    getUsers () {
      let _this = this;
      let params = {
        status: ''
      };
      _this.$http.post('api/findAllBaseUsers', params).then(res => {
        let { code, datas } = res;
        // 判断Code状态
        if (code === 0) {
          _this.users = datas;
        }
      }).catch(err => {
        if (err === undefined) {
          _this.$message({
            message: '服务器响应异常！',
            type: 'error'
          });
          return false;
        }
      });
    },
    // 返回上一步
    goBack () {
      this.$router.go(-1);
    }
  },
  created () {
    // 获取所有用户
    this.getUsers();

    // 获取节点数据
    this.getNode();
  }
};
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
